package com.association.main.service.impl;

import com.association.main.dao.UsersDao;
import com.association.main.domain.Users;
import com.association.main.service.UsersService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

@Service
public class UsersServiceImpl extends ServiceImpl<UsersDao, Users> implements UsersService {

    @Override
    public Page userList(int page, int pageSize, Users users,String sort) {

        //构建分页构造器
        Page pageInfo = new Page(page, pageSize);

        //查询条件判断-条件查询lamda表达式
        LambdaQueryWrapper<Users> usersLambdaQueryWrapper = new LambdaQueryWrapper<>();
        usersLambdaQueryWrapper.like(users.getUsername() != null, Users::getUsername, users.getUsername());
        usersLambdaQueryWrapper.like(users.getName() != null, Users::getName, users.getName());
        usersLambdaQueryWrapper.orderByDesc(Users::getCreatedAt);
        this.page(pageInfo, usersLambdaQueryWrapper);

        return pageInfo;
    }
}
